package ca.llsutherland.squash.facade;

import ca.llsutherland.squash.dao.CourtStylesDao;
import ca.llsutherland.squash.dao.GymsDao;
import ca.llsutherland.squash.dao.RolesDao;
import ca.llsutherland.squash.domain.Court;
import ca.llsutherland.squash.domain.CourtStyle;
import ca.llsutherland.squash.domain.DomainObject;
import ca.llsutherland.squash.domain.Gym;
import ca.llsutherland.squash.domain.Role;
import ca.llsutherland.squash.domain.helper.CourtsHelper;
import ca.llsutherland.squash.domain.helper.GymsHelper;
import ca.llsutherland.squash.exceptions.ValidationException;
import ca.llsutherland.squash.persistence.ReadOnlyTransactionHandler;
import ca.llsutherland.squash.persistence.Transaction;

public class FinderFacade {

    protected ReadOnlyTransactionHandler readOnlyTransactionHandler = ReadOnlyTransactionHandler.getInstance();

    public DomainObject findGym(final Gym gym) {
        GymsHelper.assertValid(gym);
        
        Transaction t = new Transaction() {
            public Object executeTransaction() throws ValidationException {
                return GymsDao.getInstance().findGym(gym);
            }
        };
        return (DomainObject) this.readOnlyTransactionHandler.runTransaction(t);
    }

    public void findCourt(final Court court) {
        CourtsHelper.assertValid(court);
    }

    public CourtStyle findCourtStyleByName(final String name) {
        Transaction t = new Transaction() {
            public Object executeTransaction() throws ValidationException {
                return CourtStylesDao.getInstance().findByName(name);
            }
        };
        return (CourtStyle) this.readOnlyTransactionHandler.runTransaction(t);
    }

    public Role findRoleByName(final String name) {
        Transaction t = new Transaction() {
            public Object executeTransaction() throws ValidationException {
                return RolesDao.getInstance().findByName(name);
            }
        };
        return (Role) this.readOnlyTransactionHandler.runTransaction(t);
        
    }
    
    
    
}
